<?php

include_once("../config.php");
include_once("functii.php");

if(isset($_GET["coord_x"]))
			{ $x = addentities($_GET["coord_x"]); }
if($x==0)
			{ $x = $coord_x; }

if(isset($_GET["coord_y"]))
			{ $y = addentities($_GET["coord_y"]); }
if($y==0)
			{ $y = $coord_y; }
// Verifica si valideaza coordonata X din harta
if($x-4>=1)
	{if($x+3<=300)
				{ $x = $x ;}
				 else
				{ $x = 297; }
	} else { $x = 4; }
////////////////////////////////////////////////
	
// Verifica si valideaza coordonata X din harta	
if($y-4>=1)
	{if($y+4<=300)
				{ $y = $y ;}
				 else
				{ $y = 297; }
	} else { $y = 4; }
////////////////////////////////////////////////
	
echo '<table border="0">';
echo '  <tr>';
echo '    <td>&nbsp;</td>';

$y1 = $y-1; 
if($y1>=4)													// filtru pentru butonul de sus a tabelului cu harta
		{ echo '    <td><center><a href="javascript:void(0)" onClick="javascript:returnare_harta('.$x.','.$y1.')" onMouseOver="javascript:animatie_but2(\'but_harta_sus\', 1,\'but_harta_sus\')" onMouseOut="javascript:animatie_but2(\'but_harta_sus\', 0,\'but_harta_sus\')"><img id= "but_harta_sus" src="img/but_harta_sus.gif" border="0" /><a/></center></td>';}
		else
		{echo '    <td><center><img src="img/but_harta_sus.gif" border="0" /></center></td>' ;}
echo '    <td>&nbsp;</td>';
echo '  </tr>';
echo '  <tr>';

$x1 = $x-1; 
if($x1>=4)													// filtru pentru butonul din stanga a tabelului cu harta
		{ echo '   <td><a href="javascript:void(0)" onClick="javascript:returnare_harta('.$x1.','.$y.')" onMouseOver="javascript:animatie_but2(\'but_harta_stanga\', 1,\'but_harta_stanga\')" onMouseOut="javascript:animatie_but2(\'but_harta_stanga\', 0,\'but_harta_stanga\')"><img id= "but_harta_stanga" src="img/but_harta_stanga.gif" border="0" /></a></td>'; }
		else
		{echo '   <td><img src="img/but_harta_stanga.gif" border="0" /></td>';}
echo '   <td>';

//////////////////////////////////////////////////
/////Inregistrare coordonate in matricea $mat de tip 7/7
//////////////////////////////////////////////////

	  $c_x1 = $x-3;	  $c_y1 = $y-3;						//////////////////////////////
	  $c_x2 = $x-2;	  $c_y2 = $y-2;						//////
	  $c_x3 = $x-1;	  $c_y3 = $y-1;						//////
	  $c_x4 = $x;	  $c_y4 = $y;						////// Memoreaza coordonatele
	  $c_x5 = $x+1;	  $c_y5 = $y+1;						//////
	  $c_x6 = $x+2;	  $c_y6 = $y+2;						//////
	  $c_x7 = $x+3;	  $c_y7 = $y+3;						/////////////////////////////

	  $c_y = $y - 4;

	  $j = 1;	

	  $query = mysql_query("SELECT * FROM `harta` LIMIT ".$c_y.",7");
	  while($rez_univers = mysql_fetch_array($query))
	  		{
			 for($i=1;$i<=7;$i++)
			 		{
					$mat[$j][$i] = $rez_univers[${"c_x".$i}];
					} 
				$j++;
			}

//////////////////////////////////////////////////
////Afisare continut matrice
//////////////////////////////////////////////////

echo ' 	   <table border="0" background="img/background_harta.jpg" cellspacing="0" cellpadding="0">';			
for($j=1;$j<=7;$j++)
		{
		 echo '<tr>';
		 for($i=1;$i<=7;$i++)
		 	 {
			 $elem = $mat[$j][$i];
			  if (($elem == "0") || ($elem == "1") || ($elem == "2") || ($elem == "3"))
			   echo '<td><img src="img/land'.$elem.'.gif" /></td>';
			  else
			   {
				$c_x = ${"c_x".$i};
				$c_y = ${"c_y".$j};
				$str_coord = "&nbsp;&nbsp;( ".${"c_x".$i}." | ".${"c_y".$j}." )";
				$rez_harta = mysql_fetch_array(mysql_query("SELECT `".$c_x."` FROM `harta` WHERE id = '".$c_y."'"));
				$rez_planeta = mysql_fetch_array(mysql_query("SELECT `nume`,`user` FROM `planete` WHERE id = '".$rez_harta[0]."'"));
			    echo '<td><img src="img/planeta_1.gif" onMouseMove="javascript:hint(\'User: '.$rez_planeta["user"].'<br>Planeta: '.$rez_planeta["nume"].'\', \'&nbsp;&nbsp;&nbsp;'.$str_coord.'<br>Distanta: '.returnare_data(calculare_distanta($coord_x, $coord_y, $c_x, $c_y, "10"), "0").'\',event)" onMouseOut="javascript:hint_hide()" onClick="javascript:status_planeta(\''.$c_x.'\', \''.$c_y.'\');" /></td>';
			   }
			 }
		 echo '</tr>';
		}
		
echo '     </table>';

/////////////////////////////////////////////////
//////////////////////////////////////////////////

echo '    </td>';

$x2 = $x+1;
if($x2<=297)										// filtru pentru butonul din dreapta a tabelului cu harta
		{  echo '    <td><a href="javascript:void(0)" onClick="javascript:returnare_harta('.$x2.','.$y.')" onMouseOver="javascript:animatie_but2(\'but_harta_dreapta\', 1,\'but_harta_dreapta\')" onMouseOut="javascript:animatie_but2(\'but_harta_dreapta\', 0,\'but_harta_dreapta\')"><img id= "but_harta_dreapta" src="img/but_harta_dreapta.gif" border="0" /></a></td>';}
		else
		{echo '    <td><img src="img/but_harta_dreapta.gif" border="0" /></td>';}
echo '  </tr>';
echo '  <tr>';
echo '    <td>&nbsp;</td>';

$y2 = $y+1;
if($y2<=297)										// filtru pentru butonul de jos a tabelului cu harta
		{ echo '    <td><center><a href="javascript:void(0)" onClick="javascript:returnare_harta('.$x.','.$y2.')" onMouseOver="javascript:animatie_but2(\'but_harta_jos\', 1,\'but_harta_jos\')" onMouseOut="javascript:animatie_but2(\'but_harta_jos\', 0,\'but_harta_jos\')"><img id= "but_harta_jos" src="img/but_harta_jos.gif" border="0" /></a></center></td>';}
		else
		{echo '    <td><center><img src="img/but_harta_jos.gif" border="0" /></center></td>';}
echo '    <td>&nbsp;</td>';
echo '  </tr>';
echo '</table>';

echo '<form id="incarcare_harta" name="form_harta" method="get" action="#" onClick="javascript:return false;">';
echo '  <label for="x_coord" class="universal">X: </label>';
echo '    <input name="x_coord" type="text" id="textfield" value="'.$x.'" size="5" maxlength="3" />';
echo '  <label for="y_coord" class="universal">Y: </label>';
echo '    <input name="y_coord" type="text" id="textfield" value="'.$y.'" size="5" maxlength="3" />';
echo '  <input type="submit" name="incarca_harta" value="Incarca Harta" onClick="javascript:returnare_harta(x_coord.value, y_coord.value);" />';
echo '</form>';

mysql_close($db);
		
?>


